package logic

import (
	"context"
	"gorm.io/gorm"
	"hotel/model/mysql"

	"hotel/hotelrpc/hotelrpc"
	"hotel/hotelrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HotelUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHotelUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HotelUpdateLogic {
	return &HotelUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HotelUpdateLogic) HotelUpdate(in *hotelrpc.HotelUpdateRequest) (*hotelrpc.HotelUpdateResponse, error) {
	// todo: add your logic here and delete this line

	hotel := mysql.Hotel{
		Model:     gorm.Model{ID: uint(in.Id)},
		Img:       in.Img,
		VipName:   in.VipName,
		Sex:       in.Sex,
		NickName:  in.NickName,
		Signature: in.Signature,
	}
	mysql.DB.Debug().Updates(&hotel)

	return &hotelrpc.HotelUpdateResponse{Id: int64(hotel.ID)}, nil
}
